import requests
import json
key="2c5e812a00f3d177e589bd4162b15249"
def geocode(key,address,city=None,batch=None)->str:
    """获取高德API的地理编码
    注释：key是指高德API的秘钥，请先去注册
          address是指结构化地址，具体请查看：https://lbs.amap.com/api/webservice/guide/api/georegeo   
    """
    url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    params = {
        "key":key,
        "address":address,
        "city":city,
        "batch":batch
    }
    response = requests.get(url,params=params)
    results = response.json()['geocodes'][0]['location']
    # 返回值
    return results

def walking(key,origin,destination,sig=None,output=None,callback=None):
    """高德API 步行路径规划
    （origin,destination是所需要转换的坐标点经纬度，output（XML）用于指定返回数据的格式，
      Key 是高德Web服务 Key。具体请查看：https://lbs.amap.com/api/webservice/guide/api/direction#walk ）"""
    url = "https://restapi.amap.com/v3/direction/walking?parameters"
    params = {'key':key, 
              'origin':origin, 
              'destination':destination,
              'sig':sig,
              'output':output,
              'callback':callback
    }
    r = requests.get(url, params=params)
    results = r.json()
    return results



